package com.atguigu.meinian.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.meinian.mapper.MemberMapper;
import com.atguigu.meinian.pojo.Member;
import com.atguigu.meinian.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zbystart
 * @create 2021-06-25 15:56
 */
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Override
    public void login(String telephone) {
        // 先根据手机号判断当前用户是否登录
        Member member = memberMapper.selectMemberInfoByPhone(telephone);
        if (member == null) {
            // 没有登录的话就注册
            member = new Member();
            member.setPhoneNumber(telephone);
            member.setRegTime(new Date());
            memberMapper.insertMember(member);
        }
    }

    @Override
    public List<Integer> selectMemberRegisterCountByMonth(ArrayList<String> months) {

        return months.stream().map(month -> memberMapper.selectMemberRegisterCountByMonth(month)
        ).collect(Collectors.toList());
    }
}
